package com.jeect.productservice.event;

import com.jeect.productservice.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RedisEventListener implements ApplicationListener<RedisEvent> {
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public void onApplicationEvent(RedisEvent event) {
        RedisUtil redisUtil = new RedisUtil(redisTemplate);
        System.out.println("onApplicationEvent.....................");
        Map<String, Map<String,Object>> map = event.getTarget();
        for(String key : map.keySet()){
            Map<String,Object> m = map.get(key);
            redisUtil.hmset(key, m);
        }
    }
}
